﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.ComponentModel.DataAnnotations;
using System.Windows;

namespace Validator.ViewModels
{
    public partial class MainViewModelC : ObservableValidator
    {
        [ObservableProperty]
        // [Required(ErrorMessageResourceName = "UserNameRequired", ErrorMessageResourceType = typeof(Lang))]
        //[MinLength(3,ErrorMessageResourceName = "UserName_MinLength", ErrorMessageResourceType =typeof(Lang))]
        [MinLength(4)]
        [MaxLength(20)]
        string? name;

        [ObservableProperty]
        [Required]
        [EmailAddress]
        string? email;

        [ObservableProperty]
        [Required]
        [Range(1, 150)]
        int age;

        [RelayCommand]
        void Register()
        {
            ValidateAllProperties();
            if (HasErrors)
            {
                //MessageBox.Show("注册失败");
                MessageBox.Show(string.Join(Environment.NewLine, GetErrors()));
            }
            else
            {
                MessageBox.Show("注册成功");
            }
        }
    }
}
